﻿@{
    ViewBag.Title = "购买随机红包服务";
}

<script src="~/Scripts/v.js"></script>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>随机红包</strong>
        <li class=""><a href="@Url.Action("Management")">管理</a></li>
        @if( ViewBag.Market != null && ( ( Himall.Model.ActiveMarketServiceInfo )ViewBag.Market ).MarketServiceRecordInfo.Max( a => a.EndTime ) >= DateTime.Now.Date )
        {
            <li class=""><a href="#" onclick="isad( '@Url.Action("Add")' )">添加代金红包</a></li>
        }
        <li class="active"><a>购买服务</a></li>
    </ul>
    @if( ViewBag.IsNo )
    {
          <form id="form1" action="@Url.Action("BuyService")" method="post">
        <div class="form-horizontal">
            <div class="form-group">
                @if( null != ViewBag.EndDate )
                {
                    <label class="col-sm-2 control-label" for="">服务到期时间：</label>
                    <div class="col-sm-2 form-control-static"><b>@ViewBag.EndDate</b></div>
                    <div class="col-sm-6"><span class="help-default">每月您需要支付<b class="red"> @ViewBag.Price.ToString( "f2" ) </b> 元，相关费用会在店铺的账期结算中扣除</span></div>
                }
                else
                {
                    <div class="col-sm-3 col-sm-offset-2 form-control-static red">您未购买优惠券服务</div>
                    <span>每月您需要支付 @ViewBag.Price.ToString( "f2" ) 元</span>
                }
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label" for="">购买数量：</label>
                <div class="col-sm-8"><input class="form-control input-sm " type="text" id="range" name="month" style="width:105px; display:inline-block" /> &nbsp; 月</div>
            </div>
            <div class="form-group">
                <div class="col-sm-3 col-sm-offset-2"><button type="submit" class="btn btn-primary">确认购买</button></div>
            </div>
        </div>
    </form>
    }
    else
    { 
        <div class="form-horizontal">
			<div class="form-group">
				<p class="apply-primary"><span class="glyphicon glyphicon-info-sign"></span>平台未开启随机红包功能</p>
			</div>
		</div>
    }
  
</div>

<script type="text/javascript">
    function isad( href )
    {
        $.post( "/SellerAdmin/ShopBonus/isadd", {}, function ( data )
        {
            if ( data )
            {
                location.href = href;
            }
            else
            {
                $.dialog.tips( '一个时间段只能新增一个随机红包！' );
            }
        } );
    }

    $( function ()
    {
        $( "#range" ).focus();
    } );
    var a = v( {
        form: 'form1',
        ajaxSubmit: true,
        beforeSubmit: function ()
        {
            loadingobj = showLoading();
        },
        afterSubmit: function ( data )
        {// 表单提交成功回调
            loadingobj.close();
            var d = data;
            if ( d.success )
            {
                $.dialog.succeedTips( "提交成功！", function ()
                {
                    window.location.reload();
                }, 0.3 );
            } else
            {
                $.dialog.errorTips( d.msg, '', 0.3 );
            }
        }
    } );
    a.add(
        {
            target: 'range',
            empty: true,
            ruleType: 'uint&&(value>0)&&(value<=3600)',// v.js规则验证
            error: '只能为数字，且只能是0到3600之间的整数!'
        } );
</script>